package com.macro.mall.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.macro.mall.dto.e.RpsBloodEntDTO;
import com.macro.mall.dto.o.RpsBloodOutDTO;
import com.macro.mall.mapper.RpsTopicFermentationResultMapper;
import com.macro.mall.model.RpsTopicFermentationResult;
import com.macro.mall.service.RpsBloodService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class RpsBloodServiceImpl implements RpsBloodService {
    @Autowired
    private RpsTopicFermentationResultMapper rpsTopicFermentationResultMapper;
    @Override
    public PageInfo<RpsBloodOutDTO> list(RpsBloodEntDTO rpsBloodEntDTO) {
        PageHelper.startPage(rpsBloodEntDTO.getPage(),rpsBloodEntDTO.getPageSize());
        List<RpsTopicFermentationResult> list = rpsTopicFermentationResultMapper.list(rpsBloodEntDTO.getDataType());
        PageInfo<RpsTopicFermentationResult> rpsTopicFermentationResultPageInfo = new PageInfo<>(list);
        List<RpsBloodOutDTO> list1 =new ArrayList<>();
        for (RpsTopicFermentationResult rpsTopicFermentationResult:list){
            RpsBloodOutDTO rpsBloodOutDTO = new RpsBloodOutDTO();
            BeanUtils.copyProperties(rpsTopicFermentationResult,rpsBloodOutDTO);
            list1.add(rpsBloodOutDTO);
        }
        PageInfo<RpsBloodOutDTO> rpsBloodOutDTOPageInfo = new PageInfo<>(list1);
        rpsBloodOutDTOPageInfo.setTotal(rpsTopicFermentationResultPageInfo.getTotal());
        return rpsBloodOutDTOPageInfo;
    }

    @Override
    public int modify(RpsBloodEntDTO rpsBloodEntDTO) {
        RpsTopicFermentationResult rpsTopicFermentationResult = new RpsTopicFermentationResult();
        BeanUtils.copyProperties(rpsBloodEntDTO,rpsTopicFermentationResult);
        return rpsTopicFermentationResultMapper.updateByPrimaryKeySelective(rpsTopicFermentationResult);
    }
}
